package com.wyw.hemerocallis.conf;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger配置类
 *  原生：/swagger-ui.html
 *  美化：/doc.html
 *
 * @author Mr Wu    yewen.wu.china@gmail.com
 * <p>
 * Update History:
 * Author        Time            Content
 */
@Configurable
@EnableSwagger2
public class SwaggerConfig {

    /**
     * Swagger实例Bean是Docket，所以通过配置Docket实例来配置Swagger
     * @return
     */
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                //展示在Swagger页面上自定义工程描述信息
                .apiInfo(apiInfo())
                .select()
                //只有com.wyw.hemerocallis包内的内容才去展示
                .apis(RequestHandlerSelectors.basePackage("com.wyw.hemerocallis"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * Swagger 的描述信息
     * @return
     */
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("hemerocallis-micro-service")
                .description("hemerocallis项目微服务")
                .contact(new Contact("Mr Wu", "wyw", "yewen.wu.china@gmail.com"))
                .version("1.0")
                .build();
    }
}
